home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9218 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.5 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Function Pointers
  5. Date: 06 Mar 1996 20:12:41 GMT
  6. Organization: Los Alamos National Laboratory
  7. Distribution: world
  8. Message-ID: <TANMOY.96Mar6131241@qcd.lanl.gov>
  9. References: <8BC3202.028600318C.uuout@mwcs.mb.ca>
  10. NNTP-Posting-Host: qcd.lanl.gov
  11. Mime-Version: 1.0
  12. Content-Type: text
  13. In-reply-to: bryan.schwartz@mwcs.mb.ca's message of Wed, 06 Mar 96 08:34:00 -0600
  14.  
  15. In article <8BC3202.028600318C.uuout@mwcs.mb.ca>
  16. bryan.schwartz@mwcs.mb.ca (BRYAN SCHWARTZ) writes:
  17.  
  18. <snip>
  19. BS: unsigned far x_get( void far *SX);   function prototype
  20.  
  21. This is a syntax error: C has no keyword called far.
  22.  
  23. <snip>
  24. BS: typedef struct vid          stuct to define screen
  25. BS: {
  26. <snip>
  27. BS:         unsigned( far * s_get)(SX) ;   function pointer in struct
  28.  
  29. This is a syntax error, far is not a keyword in C.
  30.  
  31. BS: } STRU
  32. BS: 
  33. BS: int main(void)
  34. BS: {
  35. BS:         STRU *k ;   near pointer to struct
  36. BS:         k->s_get = ( int near *)x_get ;  PROBLEM here! ????
  37.  
  38. This is a syntax error, near is not a key word in C.
  39.  
  40. Without the near, it is non portable: there is no guarantee that a
  41. function pointer can be converted to int*.
  42.  
  43. It is a constraint violation: an int* cannot be assigned to a function
  44. pointer without cast.
  45.  
  46. Try, k->sget = x_get;, or with a redundant cast, k->s_get = 
  47. (unsigned (*) (void*)) x_get.
  48.  
  49. BS:         return 0;
  50. BS: }
  51. BS: /* get a char + attribute from the screen using x_get() */
  52. BS: unsigned far x_get( SX ptr )
  53. BS: {            /* SX ptr = address in screen buffer */
  54. BS:   return( ptr->ja );
  55. BS:          /* return char + attrib. to union */
  56. BS: }
  57. BS: Shoot holes in this code, Please! And tell me about it. I'm just
  58. BS: starting learning C. How do I store a function's address in a structure
  59. BS: successfully?
  60.  
  61. If you are learning C, learn on a compiler that does C. Otherwise, you
  62. are deluding yourself thinking what you learn is the topic of this
  63. group.
  64.  
  65. If you want to know more about near/far, ask in the appropriate
  66. newsgroup (one dealing with the platform you are on).
  67.  
  68. Cheers
  69. Tanmoy
  70. --
  71. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  72. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  73. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  74. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  75. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  76. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  77.